package hello;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.Session;
import org.hibernate.Transaction;

import persistence.HibernateUtil;
import auction.model.BidAsMapValue;
import auction.model.ItemWithMapValueEntity;

public class HelloWorldMapValueEntity
{
	
	
	public static void main(String[] args)throws Exception
	{
		
		Session s=HibernateUtil.getSessionFactory().openSession();
		Transaction tx=s.beginTransaction();
		
		
		
		ItemWithMapValueEntity itemValueType=new ItemWithMapValueEntity();
		Map<Long,BidAsMapValue> bidMap=new HashMap<Long,BidAsMapValue>();
		
		BidAsMapValue bi =new BidAsMapValue();
		
		
		s.save(bi);
		
		bidMap.put(bi.getBid(), bi);
		itemValueType.setBidMap(bidMap);
		
		s.save(itemValueType);
		
		tx.commit();
		s.close();
		
		
		
		Session s1=HibernateUtil.getSessionFactory().openSession();
		Transaction tx1=s1.beginTransaction();
		
		ItemWithMapValueEntity loaded=(ItemWithMapValueEntity)s1.load(ItemWithMapValueEntity.class, 1L);
		out("########"+loaded.getBidMap().size()+" "+loaded.getBidMap());
		
		tx1.commit();
		s1.close();
		
		
		
		//HibernateUtil.stat();
		HibernateUtil.shutdown();
	}
	
	public static void getParent(Class clazz)
	{
		Class parent=clazz.getSuperclass();
	  if(parent !=null)
	  {
			System.out.println("###"+parent.getName());
			getParent(parent);
		}
	}
	
	static void out(Object obj)
	{
		System.out.println(obj);
	}
}
